﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsGameAula02
{
    class Enemy: AnimatedObject2D
    {
        Player target;
        //Vector2 dir;
        public Enemy(Texture2D t, Vector2 p, Animation[] a)
            : base(t, p, a)
        {

        }

        public void Update(Player tar, GameTime gameTime)
        {
            target = tar;
            if (Vector2.Distance(tar.Position, Position) <= 75)
            {
                //return;
            }
            else
            {
                Move(new Vector2((float)Math.Sin(Rotation), -(float)Math.Cos(Rotation)), 3f);
            }
            
            //Rotation = (float)Math.Atan2(tar.Position.Y - Position.Y, tar.Position.X - tar.Position.X);
            //dir = new Vector2((float)Math.Cos(Rotation), -(float)Math.Sin(Rotation));

            Vector2 hypotenuse;
            hypotenuse.X = tar.Position.X - Position.X;
            hypotenuse.Y = Position.Y - tar.Position.Y;
            float rotation = (float)Math.Atan2(hypotenuse.X, hypotenuse.Y);
            Rotation = rotation;

            base.Update(gameTime);
        }

        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            base.Draw(spriteBatch, gameTime);
        }

        public void Move(Vector2 dir, float speed)
        {
            if (speed == 0) return;
            this.Position += dir * speed;
        }
    }
}
